using System;
using System.Collections.Generic;
using System.Text;

namespace Decav.Reality
{
    /// <summary>
    /// A <see cref="StreetAddress"/> that is in the United States of America.
    /// </summary>
    [Serializable]
    public class UsStreetAddress : StreetAddress
    {
        public UsStreetAddress()
            : base()
        {
        }

        public UsStreetAddress(string address1, string address2, string city,
            UsState state, string postalCode, string county)
            : base(address1, address2, city, state.PostalCode, postalCode, Country.FromCountryCode("USA"), county)
        {
        }

        /// <summary>
        /// Gets or sets the region of the address.
        /// </summary>
        public override string Region
        {
            get
            {
                return base.Region;
            }
            set
            {
                try
                {
                    UsState.FromPostalCode(value);
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException("Cannot set a Region in a UsStreetAddress that is not a valid US state.", ex);
                }

                base.Region = value;
            }
        }

        /// <summary>
        /// Gets or sets the United States state of the address.  This is the same as the <see cref="Region"/>.
        /// </summary>
        public UsState State
        {
            get
            {
                return UsState.FromPostalCode(Region);
            }
            set
            {
                Region = value.PostalCode;
            }
        }
    }
}
